package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ajax")
public class AjaxTest extends HttpServlet
{
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("接受ajax请求...");
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setHeader("content-type", "text/html;charset=utf-8");

        String appkey =req.getHeader("appKey"+"123"+"ASD");
        if (appkey == null){
            resp.getWriter().write("请求不合法！！");
            return;

        }
        String name = "锐雯";
        String age = "20";
        String sex = "女";

        String json = "{\"firstName\":\""+name+"\",\"age\":"+age+",\"sex\":"+sex+"\"}";

        resp.getWriter().write(json);

    }

}
